Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(web): display errors msg got from be #1343

Merged
merged 58 commits into from
Jan 22, 2025

Conversation

soneda-yuya
Copy link
Contributor

@soneda-yuya soneda-yuya commented Jan 9, 2025

Overview

write overview on this pr.
#1342

What I've done

  • display errors got from backend

What I haven't done

How I tested

  • confirm display error message got from backend by each lang
2025-01-22.17.35.11.1.mov

Which point I want you to review particularly

Memo

Summary by CodeRabbit

Release Notes

  • New Features

    • Added language-specific headers to GraphQL requests.
    • Enhanced error handling to support multiple error tracking.
  • Bug Fixes

    • Improved error reporting mechanism across the application.
    • Updated error message handling and translations.
  • Refactor

    • Transitioned from single error state to multi-error error management.
    • Updated error handling hooks and functions.
  • Documentation

    • Removed generic error messages in translation files.

The release introduces more robust error tracking and improved internationalization support.

Copy link

coderabbitai bot commented Jan 9, 2025

Warning

Rate limit exceeded

@soneda-yuya has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 34 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 3cde5d3 and 2ccaeed.

📒 Files selected for processing (1)
  • web/src/beta/features/Notification/hooks.ts (3 hunks)

Walkthrough

This pull request introduces a comprehensive overhaul of error handling mechanisms across multiple files in the web application. The primary change is transitioning from a single-error to a multi-error management approach. This involves modifying error-related functions, atoms, and hooks to support arrays of errors, adding more detailed error information, and updating error reporting and notification systems. A new langLink is also introduced to handle language-specific GraphQL request headers.

Changes

File Change Summary
web/src/beta/features/Notification/hooks.ts Updated to handle multiple errors using useErrors() instead of useError()
web/src/sentry.ts Modified reportError() to accept an array of errors
web/src/services/gql/provider/index.tsx Added langLink to Apollo Client configuration
web/src/services/gql/provider/links/errorLink.ts Refactored to manage multiple errors with enhanced error details
web/src/services/gql/provider/links/langLink.ts New file with language header injection for GraphQL requests
web/src/services/i18n/translations/en.yml Removed generic error message
web/src/services/i18n/translations/ja.yml Removed generic error message
web/src/services/state/gqlErrorHandling.ts Major refactoring of error handling types and atoms
web/src/services/state/index.ts Updated exports for error handling

Sequence Diagram

sequenceDiagram
    participant Client
    participant GraphQLProvider
    participant ErrorLink
    participant Sentry
    participant Notifications

    Client->>GraphQLProvider: Make GraphQL Request
    GraphQLProvider->>ErrorLink: Process Request
    alt Network Error
        ErrorLink-->>Sentry: Report Network Error
        ErrorLink-->>Notifications: Create Error Notification
    else GraphQL Errors
        ErrorLink->>ErrorLink: Transform Errors
        ErrorLink-->>Sentry: Report Multiple Errors
        ErrorLink-->>Notifications: Create Error Notifications
    end
Loading

Possibly related PRs

  • feat(web): Export & Import Project #1154: The changes in this PR involve modifications to error handling in the Projects component, which may relate to the enhanced error handling introduced in the main PR's Notification hook that now accommodates multiple errors.
  • fix(web): improve project import  #1199: This PR updates the handleImportProject function to include a teamId parameter, which aligns with the main PR's focus on managing multiple errors and improving the handling of project-related functionalities.
  • feat(web): add env var to control the display of workspace management pages #1203: The introduction of an environment variable to control workspace management visibility may relate to the error handling improvements in the main PR, as both involve managing application state and user interactions.

Suggested reviewers

  • mkumbobeaty
  • airslice
  • mulengawilfred

Poem

🐰 Errors dance in arrays so bright,
No longer solo, now taking flight!
Language links and headers sing,
Multi-error handling takes its wing!
Code evolves with rabbit might! 🚀


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the web label Jan 9, 2025
@soneda-yuya soneda-yuya changed the title refactor(web): [FE]Improvement: display error msg with translations o… refactor(web): [FE]Improvement: display error msg with translations Jan 9, 2025
@soneda-yuya soneda-yuya changed the title refactor(web): [FE]Improvement: display error msg with translations refactor(web): [FE] Improvement: display error msg with translations Jan 9, 2025
@soneda-yuya soneda-yuya changed the title refactor(web): [FE] Improvement: display error msg with translations refactor(web): [FE] display error msg got from be Jan 10, 2025
@soneda-yuya soneda-yuya changed the title refactor(web): [FE] display error msg got from be refactor(web): [FE] display errors msg got from be Jan 10, 2025
@soneda-yuya soneda-yuya force-pushed the refactor/error_handling_be branch 6 times, most recently from 51ba37d to eb619f0 Compare January 17, 2025 12:34
@soneda-yuya soneda-yuya force-pushed the refactor/error_handling_be branch from eb619f0 to 0ae0aed Compare January 17, 2025 16:21
Base automatically changed from refactor/error_handling_be to main January 22, 2025 08:46
@soneda-yuya soneda-yuya dismissed airslice’s stale review January 22, 2025 08:46

The base branch was changed.

@soneda-yuya soneda-yuya requested a review from pyshx as a code owner January 22, 2025 08:46
@github-actions github-actions bot removed the server label Jan 22, 2025
Copy link

netlify bot commented Jan 22, 2025

Deploy Preview for reearth-web ready!

Name Link
🔨 Latest commit 2ccaeed
🔍 Latest deploy log https://app.netlify.com/sites/reearth-web/deploys/6790b7bc991c1f0008250fd2
😎 Deploy Preview https://deploy-preview-1343--reearth-web.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

🧹 Nitpick comments (6)
web/src/services/gql/provider/links/langLink.ts (1)

5-13: Add TypeScript types for better type safety.

Consider adding explicit type definitions for the context and headers:

+  interface Headers {
+    [key: string]: string;
+  }
+
+  interface Context {
+    headers?: Headers;
+  }

-  return setContext(async (_, { headers }) => {
+  return setContext(async (_, { headers }: Context) => {
web/src/sentry.ts (1)

15-26: Improve type checking in error handling.

While the array-based error reporting looks good, the type checking could be enhanced:

  1. The instanceof Error check might not catch all error types since error is of type ReportError
  2. The type definition suggests error should have type and message properties

Consider this implementation:

 export const reportError = (errors: ReportError[]) => {
   errors.forEach((error) => {
-    if (error instanceof Error) {
+    if (error instanceof Error || error.constructor?.name === 'Error') {
       Sentry.captureException(error);
     } else {
       Sentry.captureException(
         new Error(
           `${error.type || "Unknown"}: ${error.message || "No message provided"}`
         )
       );
     }
   });
 };
web/src/services/gql/provider/links/errorLink.ts (1)

14-16: Improve null-safety in network error handling.

The optional chaining on networkError?.message is redundant in the array initialization since it's already checked in the condition.

 if (networkError?.message) {
   errors = [
-    { message: networkError?.message, description: networkError.message }
+    { message: networkError.message, description: networkError.message }
   ];
web/src/beta/features/Notification/hooks.ts (3)

26-26: Consider adding explicit type annotations for better type safety.

While the code works, adding explicit type annotations would improve type safety and code documentation.

-  const [errors, setErrors] = useErrors();
+  const [errors, setErrors] = useErrors<Array<{ message?: string; description?: string }>>();

54-55: Consider deduplicating error messages.

When processing multiple errors, consider deduplicating similar messages to prevent notification spam.

-    errors.forEach((error) => {
+    const uniqueErrors = errors.filter((error, index, self) =>
+      index === self.findIndex(e => e.message === error.message)
+    );
+    uniqueErrors.forEach((error) => {

70-82: Consider prioritizing error notifications.

The current implementation shows all errors sequentially. Consider prioritizing critical errors or grouping similar errors.

+      const errorPriority = error.message?.includes("policy violation") ? 1 : 2;
+      const notification = {
+        priority: errorPriority,
         type: error.message?.includes("policy violation") ? "info" : "error",
         heading: error.message?.includes("policy violation") ? noticeHeading : errorHeading,
         text: error.message?.includes("policy violation") ? message : (error.description || error.message || ""),
         ...(error.message?.includes("policy violation") && { duration: "persistent" })
+      };
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 70d3dcd and 3c43ea1.

📒 Files selected for processing (9)
  • web/src/beta/features/Notification/hooks.ts (3 hunks)
  • web/src/sentry.ts (1 hunks)
  • web/src/services/gql/provider/index.tsx (2 hunks)
  • web/src/services/gql/provider/links/errorLink.ts (1 hunks)
  • web/src/services/gql/provider/links/langLink.ts (1 hunks)
  • web/src/services/i18n/translations/en.yml (0 hunks)
  • web/src/services/i18n/translations/ja.yml (0 hunks)
  • web/src/services/state/gqlErrorHandling.ts (1 hunks)
  • web/src/services/state/index.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • web/src/services/i18n/translations/ja.yml
  • web/src/services/i18n/translations/en.yml
🔇 Additional comments (7)
web/src/services/gql/provider/index.tsx (1)

17-17: LGTM! The langLink integration looks good.

The langLink is appropriately positioned in the Apollo link chain, after authentication and before the upload link. This ensures that language headers are added to authenticated requests.

Also applies to: 94-94

web/src/services/state/gqlErrorHandling.ts (2)

4-9: LGTM! Enhanced error type definition.

The expanded GQLError type with additional fields (code and description) provides more comprehensive error information.


10-11: Verify the migration from single error to error array.

The transition to array-based error management looks good, but ensure all consumers of the old useError hook are updated to use useErrors.

Also applies to: 14-15

✅ Verification successful

Migration to array-based error management is complete

All occurrences of the old useError hook have been properly migrated to the new useErrors hook. No remaining usages of the old hook were found in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining usage of the old useError hook
rg "useError" --type ts

Length of output: 463

web/src/services/gql/provider/links/errorLink.ts (1)

18-26: LGTM! Comprehensive GraphQL error mapping.

The error mapping implementation effectively captures all relevant error information from GraphQL errors, including type, message, code, and description.

web/src/services/state/index.ts (1)

8-8: LGTM! Clean export update.

The removal of useError export and retention of useSetError aligns with the new array-based error handling approach.

web/src/beta/features/Notification/hooks.ts (2)

2-3: LGTM! Import changes align with multi-error handling.

The transition from useError to useErrors correctly supports the new multi-error handling approach.


86-91: LGTM! Dependencies are properly maintained.

All dependencies used in the effect are correctly listed in the dependency array.

web/src/services/gql/provider/links/langLink.ts Outdated Show resolved Hide resolved
web/src/services/gql/provider/links/langLink.ts Outdated Show resolved Hide resolved
web/src/beta/features/Notification/hooks.ts Outdated Show resolved Hide resolved
@soneda-yuya soneda-yuya force-pushed the refactor/error_handling_fe branch from b110bd7 to 2ccaeed Compare January 22, 2025 09:17
@soneda-yuya soneda-yuya requested a review from airslice January 22, 2025 09:29
@soneda-yuya soneda-yuya merged commit 1d93e86 into main Jan 22, 2025
17 checks passed
@soneda-yuya soneda-yuya deleted the refactor/error_handling_fe branch January 22, 2025 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants